<template>
      <div class="log app-body">
            <el-col :span="24" class="button-box">
                  <el-button type="danger" icon="el-icon-delete" size="mini" @click="delList">批量删除</el-button>
            </el-col>
            <el-table @selection-change="handleSelectionChange" size="mini" :header-cell-style="$setting.table_header" :stripe="true" :fit="true" :data="tableData" border style="width: 100%">
                  <el-table-column type="selection" width="55"></el-table-column>
                  <el-table-column fixed prop="id" label="编号"></el-table-column>
                  <el-table-column prop="time" label="时间" :formatter="formatDate"></el-table-column>
                  <el-table-column prop="admin" label="操作人"></el-table-column>
                  <el-table-column prop="active" label="操作日志"></el-table-column>
                  <el-table-column label="操作">
                        <template slot-scope="scope">
                              <!-- <el-button size="mini" type="warning" icon="el-icon-edit" circle @click.native="edit(scope.row)"></el-button> -->
                              <el-button size="mini" type="danger" icon="el-icon-delete" circle @click.native="del(scope.row)"></el-button>
                        </template>
                  </el-table-column>
            </el-table>
            <div class="page-box">
                  <el-pagination :hide-on-single-page="true" @current-change="changePage" background layout="prev, pager, next" :total="total" :page-size="15"></el-pagination>
            </div>
      </div>
</template>

<script>
export default {
      props: [],
      data() {
            return {
                  tableData:[],
                  total:0,
                  pageSize:15,// 每页的数量
                  page:0,// 页码，从零开始
                  isChange:false,
                  multipleSelection:[],
            }
      },
      methods:{
            /**格式化日期 */
            formatDate(row){
                  let date=new Date(row.time);
                  let month=(date.getMonth()+1)<10?'0'+(date.getMonth()+1):(date.getMonth()+1);
                  let day=date.getDate()<10?'0'+date.getDate():date.getDate();
                  let hours=date.getHours()<10?'0'+date.getHours():date.getHours();
                  let minutes=date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes();
                  return date.getFullYear()+'-'+month+'-'+day+' '+hours+':'+minutes;
            },
            /**批量删除 */
            delList(){
                  this.$confirm('此操作将永久删除信息, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                  }).then(() => {
                        this.$root.loading=true;
                        let format=new FormData();
                        this.multipleSelection.forEach(item=>{
                              format.append("id",item.id);
                        })
                        format.append("page",this.page);
                        format.append("pageSize",this.pageSize);

                        this.$axios({
                              method:'DELETE',
                              data:format,
                              url:this.$url+"admin/log/delAdmin",
                        }).then(
                              (res)=>{
                                    this.$root.loading=false;
                                    this.tableData=res.data.data.logList;
                                    this.totle=res.data.data.total;
                                    this.$message({
                                          type:'success',
                                          message:'删除成功'
                                    })
                              }
                        )
                  })

            },
            del(row){
                  this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                  }).then(() => {
                        this.$root.loading=true;
                        let format=new FormData();
                        format.append("id",row.id);
                        format.append("page",this.page);
                        format.append("pageSize",this.pageSize);

                        this.$axios({
                              method:'DELETE',
                              data:format,
                              url:this.$url+"admin/log/delAdmin",
                        }).then(
                              response=>{
                                    this.tableData=response.data.data.logList
                                    this.total=response.data.data.total;
                                    this.$root.loading=false;
                                    this.$message({
                                          type:'success',
                                          message:response.data.status.message
                                    })
                              }
                        )
                  })
            },
            /**监听页码发生变化 */
            changePage(e){
                  this.page=e-1;
                  this.toPage();
            },
            /**请求当前页码的数据 */
            toPage(){
                  this.$axios.get(this.$url+'/admin/log/adminList?pageSize='+this.pageSize+'&page='+this.page).then(
                        response=>{
                              this.tableData=response.data.data.logList;
                              this.total=response.data.data.total;
                        }
                  )
            },
            init(){
                  this.toPage();
            },
            /**选择框 val为当前所有选择的内容数组 */
            handleSelectionChange(val) {
                  this.multipleSelection = val;
            },
      },
      mounted(){
            this.init();
      }
};
</script>

<style lang="less">
.page-box{
      padding: 20px 0;
      text-align: right;
}
</style>